package cn.kgc.controller;

import cn.kgc.client.ScoreClient;
import cn.kgc.entity.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/6/28
 * @Description: openfeign 组件实现服务间的通信
 */
@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired(required = false)
    private ScoreClient scoreClient;

    @RequestMapping("m1")
    public String  method1(Integer id){
        System.out.println("id = " + id);
        String result = scoreClient.getById(id);
        return "StudentController ok  result = "+result;
    }


    @RequestMapping("m2")
    public String  method2(Integer id){
        System.out.println("id = " + id);
        String result = scoreClient.getById2(id);
        return "StudentController ok  result = "+result;
    }

    @RequestMapping("m3")
    public String  method3(Score score){
        System.out.println("score = " + score);
        String result = scoreClient.addScore(score);
        return "StudentController ok  result = "+result;
    }


    @RequestMapping("m4")
    public String  method4(String name){
        System.out.println("name = " + name);
        // http://localhost:8504/score/select?name=java
        // {"course":"java","score":90,"id":10}
        Score score = scoreClient.selectByCourseName(name);
        System.out.println("score = " + score);
        return "StudentController ok  result = "+score;
    }



}
